package com.mr235.widgetdemo;

import android.app.IntentService;
import android.app.Service;
import android.content.Intent;
import android.content.Context;
import android.os.IBinder;
import android.widget.Toast;

import androidx.annotation.Nullable;

/**
 * An {@link IntentService} subclass for handling asynchronous task requests in
 * a service on a separate handler thread.
 * <p>
 * <p>
 * TODO: Customize class - update intent actions, extra parameters and static
 * helper methods.
 */
public class WidgetService extends Service {

    private static int status = 0;

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent != null) {
            String action = intent.getStringExtra("action");
            if ("充电".equals(action)) {
                Toast.makeText(getApplicationContext(), "充电，当前状态" + status % 3, Toast.LENGTH_SHORT).show();
            } else if ("回家".equals(action)) {
                Toast.makeText(getApplicationContext(), "回家，当前状态" + status % 3, Toast.LENGTH_SHORT).show();
            }
            status++;
        }
        return super.onStartCommand(intent, flags, startId);
    }
}